<script setup>
import { RouterLink, RouterView } from 'vue-router'
import { ref } from 'vue'

const wrapper_show = ref(false)
function wrapper_open(value = 0) {
  if (window.innerWidth <= 1000) {
    setTimeout(() => {
      if (wrapper_show.value == true) {
        wrapper_show.value = false
        unlockScroll()
      } else {
        wrapper_show.value = true
        lockScroll()
      }
    }, value);
  }
}
function lockScroll() {
  let widthBar = 17, root = document.documentElement;
  if (typeof window.innerWidth == 'number') {
    widthBar = window.innerWidth - root.clientWidth;
  }
  root.style.overflow = 'hidden';
  root.style.borderRight = widthBar + 'px solid transparent';
}
function unlockScroll() {
  let root = document.documentElement;
  root.style.overflow = '';
  root.style.borderRight = '';
}
</script>

<template>
  <header>
    <a class="hover_777 a color_black wrapper_button" @click="wrapper_open()">
      <el-icon class="w100_h100">
        <Expand class="w100_h100" />
      </el-icon>
    </a>
    <RouterLink to="/" replace class="logo noSelectA">Rxaser</RouterLink>
    <div class="wrapper_bg" v-show="wrapper_show" @click="wrapper_open()"></div>
    <div class="wrapper" :class="{ wrapper_open: wrapper_show }">
      <nav>
        <RouterLink to="/" @click="wrapper_open(100)" replace class="animation_a">主 页</RouterLink>
        <RouterLink to="/publish" @click="wrapper_open(100)" replace class="animation_a">发 布</RouterLink>
        <RouterLink to="/chat" @click="wrapper_open(100)" replace class="animation_a">聊 天</RouterLink>
        <RouterLink to="/about" @click="wrapper_open(100)" replace class="animation_a">关 于</RouterLink>
      </nav>
      <div class="login_reg">
        <a href="" class="animation_a">登录</a>
        <a href="" class="animation_a">注册</a>
      </div>
    </div>
  </header>

  <router-view v-slot="{ Component }">
    <Transition name="Transition_1">
      <keep-alive>
        <component :is="Component" />
      </keep-alive>
    </Transition>
  </router-view>


</template>

<style scoped>
header {
  position: relative;
  max-height: 100vh;
  background-color: #d2d2d2;
  padding-block: 10px;
  display: flex;
  align-items: center;
  box-shadow: 0 1px 10px #858585;
}

.wrapper_button {
  display: none;
  left: 20px;
  padding: 3px;
  margin: 0;
  height: 38px;
  width: 38px;
  border: 1px solid;
}

.logo {
  width: 154px;
  font-size: 30px;
  border-right: 2px solid;
  padding-left: 20px;
  padding-right: 20px;
  font-family: "MonaspaceRadon_Bold";
  color: #fff;
  --text-shadow: #909090;
  text-shadow:
    -1px -1px 0 var(--text-shadow),
    1px -1px 0 var(--text-shadow),
    -1px 1px 0 var(--text-shadow),
    1px 1px 0 var(--text-shadow);
}

.wrapper {
  padding-left: 30px;
  padding-right: 30px;
  display: flex;
  justify-content: space-between;
  width: 100%;
  font-weight: lighter;
}

.wrapper_bg {
  display: none;
}

.wrapper_shower {
  display: none;
}

nav {
  text-align: center;
  font-size: 20px;
  display: flex;
  align-items: center;
}

nav a.router-link-exact-active {
  color: var(--color-text);
  animation: none;
  border-color: var(--color-text);
}

nav a.router-link-exact-active:hover {
  background-color: transparent;
}

nav a {
  font-weight: 600;
  padding: 0 .3cm;
  margin-inline: 3px;
}

.login_reg {
  display: flex;
  align-items: center;
  font-size: 18px;
  border-color: var(--color-border-hover);
  border-left: 1px solid;
  padding-left: 10px;
}

/* 下面我们会解释这些 class 是做什么的 */
.Transition_1-enter-active {
  transition: 1s ease;
}

.Transition_1-leave-active {
  transition: none;
}

.Transition_1-enter-from,
.Transition_1-leave-to {
  opacity: 0;
  transform: scale(0.95);
}


@media screen and (max-width: 1000px) {
  header {
    padding-block: 0;
  }

  .wrapper_button {
    display: block;
    position: absolute;
  }

  .logo {
    border: none;
    width: fit-content;
    margin: auto;
  }

  .wrapper {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 999;
    padding: 10px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: start;
    width: 150px;
    height: 100vh;
    background-color: #dedede;
    transform: translateX(-100%);
    transition: 0.3s;
  }

  .wrapper_open {
    transform: translateX(0%);
  }

  .wrapper_bg {
    display: block;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 999;
    width: 100vw;
    height: 100vh;
    background-color: #00000062;
  }

  .wrapper_shower {
    display: block;
    width: 100%;
    height: 32px;
    margin-bottom: 20px;
    display: flex;
    justify-content: end;
  }

  .wrapper_button1 {
    height: 34px;
    border: 1px solid;
    border-radius: 0;
    margin: 0 10px;
    transition: 0.2s;
  }

  .wrapper_button1:hover {
    border-color: var(--vt-c-hove-color1);
  }

  a {
    display: inline-block;
  }

  nav,
  .login_reg {
    width: 60%;
    display: flex;
    flex-direction: column;
    border: 0;
  }

  .login_reg {
    border-top: 1px solid;
    margin-top: 10px;
    padding-top: 10px;
    padding-left: 0;
  }
}
</style>
